package com.easylinkin.linkappapi.openapi.controller;

import com.easylinkin.linkappapi.common.utils.message.SendEmailUtil;
import com.easylinkin.linkappapi.openapi.service.SynchronizationLinkthingService;
import com.easylinkin.linkappapi.tenant.entity.LinkappTenant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * class info :测试异步调用设备同步接口逻辑
 *
 * @author liuqihang
 * @date 2021/8/13 15:08
 */
@RestController
@Slf4j
@RequestMapping("/tenantTest")
public class TestSyncController {

    @Resource
    private SynchronizationLinkthingService synchronizationLinkthingService;
    @Resource
    private SendEmailUtil sendEmailUtil;

    @PostMapping("test")
    public RestMessage update(HttpServletRequest request, @RequestBody LinkappTenant tenant) {
        //AEP初始化设备同步--异步调用
        synchronizationLinkthingService.syncDeviceAndUnitByProject(request, tenant);
        log.info("结束..............");
        return RestBuilders.successBuilder().message("success").build();
    }

    /**
     * 邮件测试
     * @param request
     * @param tenant
     * @return
     */
    @PostMapping("test1")
    public RestMessage test1(HttpServletRequest request, @RequestBody LinkappTenant tenant) {
//        sendEmailUtil.send();
        return RestBuilders.successBuilder().message("success").build();
    }
}
